package cn.cmdr.service.ServiceImpl;

import cn.cmdr.mapper.ComMapper;
import cn.cmdr.pojo.Commodity;
import cn.cmdr.service.RecoveryService;
import cn.cmdr.vo.ComVo;
import cn.cmdr.vo.PageVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("recoveryService")
public class RecoveryServiceImpl extends ServiceImpl<ComMapper, Commodity> implements RecoveryService {
    @Resource
    private ComMapper comMapper;

    @Override
    public PageVo getPageComList(Integer pageNo, Integer pageSize, ComVo comVo) {
        Page page = new Page();
        page.setSize(pageSize);
        page.setCurrent(pageNo);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.like(!StringUtils.isEmpty(comVo.getName()),"name",comVo.getName())
                .like(comVo.getProductSn()!=null,"product_sn", comVo.getProductSn())
                .eq(comVo.getProductCategoryId()!=null," product_category_id", comVo.getProductCategoryId())
                .eq(comVo.getBrandId()!=null,"brand_Id",comVo.getBrandId())
                .eq(comVo.getPublishStatus()!=null,"publish_status",comVo.getPublishStatus())
                .eq(comVo.getVerifyStatus()!=null,"verify_status",comVo.getVerifyStatus())
                .eq(comVo.getVerifyStatus()!=null,"verify_status",comVo.getVerifyStatus())
                .eq(true,"delete_status",1)
                .orderByDesc("c.sort");
        List<Commodity> list = comMapper.getComPageList(page,queryWrapper);
        return new PageVo(list,page.getTotal());
    }
}
